﻿// <copyright file="QldFederalResultsByElectorate2004FileDefinitionTest.cs" company="QUT">
//     Copyright (c) Ninety Nine Percent. All rights reserved.
// </copyright>

namespace Qut.GenerateKml.Data
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Text;
    using FileHelpers.DataLink;
    using NUnit.Framework;

    /// <summary>
    /// A class for testing QldFederalResultsByElectorate2004FileDefinition class. 
    /// </summary>
    [TestFixture]

    public class QldFederalResultsByElectorate2004FileDefinitionTest
    {
        /// <summary>
        /// SociologicalData sociological
        /// </summary>
        private SociologicalData sociological;

        /// <summary>
        /// Initializes the all data member in the test.
        /// </summary>
        [SetUp]
        public void Initialize()
        {
            this.sociological = new SociologicalData();
        }

        /// <summary>
        /// Test load(): Count rows
        /// </summary>
        [Test]
        public void Load_Count()
        {
            this.sociological.PreloadQldFederalResultsByElectorate2004("Qld_FederalResults by Electorate-2004.xls");
            var results = from r in this.sociological.Database.QldFederalResultsByElectorate2004s
                          select r;

            Assert.AreEqual(28, results.Count());
        }

        /// <summary>
        /// Test load: first and last element
        /// </summary>
        [Test]
        public void Load_FirstLastElement()
        {
            this.sociological.PreloadQldFederalResultsByElectorate2004("Qld_FederalResults by Electorate-2004.xls");
            var results = from r in this.sociological.Database.QldFederalResultsByElectorate2004s
                          select r;

            string firstDvision = string.Empty;

            foreach (var result in results)
            {
                firstDvision = result.Division;
                break;
            }

            Assert.AreEqual(firstDvision, "Blair");

            string lastDivision = string.Empty;
            foreach (var result in results)
            {
                lastDivision = result.Division;
            }

            Assert.AreEqual(lastDivision, "Wide Bay");
        }     
    }
}

